/*
 * @Description: test
 * @Author: rendc
 * @Date: 2024-08-01 09:04:54
 * @LastEditors: rendc
 * @LastEditTime: 2024-08-01 10:23:07
 */
// 对象创建的方式
// 字面量
var obj = {
  name: "zs",
  age: 14,
  sayName: function () {
    console.log("my name is ", this.name);
  }
}
obj.name = "zsNew";
obj.gender = "男";
delete obj.age;
console.log('🤡 CC - obj:', obj);
obj.sayName();
// 构造函数
var obj1 = new Object();
obj1.name = "ls";
obj1.age = 12;
obj1.sayName = function () {
  console.log("my name is ", this.name);
}
console.log('🤡 CC - obj1:', obj1);

console.log('🤡 CC - obj1.name:', obj1.name);
console.log('🤡 CC - obj1["name"]:', obj1['name']);

function getObjProp (key) {
  console.log('🤡 CC - getObjProp - key:', key);
  var value;
  value = obj1[key];
  console.log('🤡 CC - getObjProp - value:', value);
}
getObjProp('name');
getObjProp('age');
// console.log('🤡 CC - obj1["name"]:', obj1['name']);

obj1.sayName();
console.log('🤡 CC - obj1.sayName:', obj1.sayName);
// var obj={};
// obj.name="terry";
// obj.age=12;

for (var key in obj1) {
  var value = obj1[key];
  console.log('🤡 CC - key:value:', key + ':' + value);
}


var arr = [1, 2, 3]

// obj2 = null;
obj2 = {};

if (obj2 == {} || obj2 == null) {

}

console.log('🤡 CC - obj1?.name:', obj1?.name);
console.log('🤡 CC - obj2?.name:', obj2?.name);
console.log('🤡 CC - "name" in obj2:', "name" in obj2);

console.log('🤡 CC - obj.toString():', obj.toString());


// 对象序列化
var dog = {
  name: "狗子",
  age: 1,
  color: "black",
  type: "哈士奇",
  run: function () {
    console.log('🤡 CC - dog.run:二哈在奔跑');
  },
  eat: function () {
    console.log('🤡 CC - dog.eat:二哈在吃沙发');
  }
}
// {"name":"狗子","age":1,"color":"black","type":"哈士奇"}

console.log('🤡 CC - dog:', dog);
var jsonDog = JSON.stringify(dog);
console.log('🤡 CC - jsonDog:', jsonDog);
console.log('🤡 CC - jsonDog.name:', jsonDog.name);
console.log('🤡 CC -typeof jsonDog:', typeof jsonDog);


var dogNew = JSON.parse(jsonDog);
console.log('🤡 CC - dogNew:', dogNew);
console.log('🤡 CC - dogNew.name:', dogNew.name);
